import {combineReducers} from 'redux'
import theme from './theme'
import {rootCom, RootNavigator} from '../navigator'
import popularReducer from './popular'
import trendingReducer from './trending'
import favoriteReducer from './favorite'

/**
 * 1.指定默认的state
 */
const navState = RootNavigator.router.getStateForAction(RootNavigator.router.getActionForPathAndParams(rootCom))

/**
 * 2.创建自己的 navigation reducer
 */
const navReducer = (state = navState, action) => {
    const nextState = RootNavigator.router.getStateForAction(action, state)
    //如果nextState为null或者未定义，返回原始state
    return nextState || state
}


/**
 * 合并reducer
 */
const reducer = combineReducers({
    nav: navReducer,
    theme: theme,
    popular: popularReducer,
    trending: trendingReducer,
    favorite: favoriteReducer,

})

export default reducer;
